package com.jiaquyun.jcyx.main.mine

import androidx.lifecycle.LifecycleOwner
import com.blankj.utilcode.util.ActivityUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.jiaquyun.jcyx.R
import com.jiaquyun.jcyx.entity.ArticleList
import com.jiaquyun.jcyx.jetpack.mode.ArticleViewModel
import com.module.lemlin.http.Status
import com.module.lemlin.owner.OwnerViewModeActivity
import kotlinx.android.synthetic.main.activity_mine_help.*

class MineHelpActivity : OwnerViewModeActivity<ArticleViewModel>() {

    companion object {
        fun open() {
            ActivityUtils.startActivity(MineHelpActivity::class.java)
        }
    }

    private val mHelpAdapter =
        object : BaseQuickAdapter<ArticleList, BaseViewHolder>(R.layout.item_feedback_help) {
            override fun convert(holder: BaseViewHolder, item: ArticleList) {
                holder.setText(R.id.tvFeedbackHelpName, item.title)
            }
        }

    override fun viewModel(): ArticleViewModel {
        return createViewModel()
    }

    override val layoutResId: Int
        get() = R.layout.activity_mine_help

    override fun stateBar(): StatusBar {
        return StatusBar(isLightMode = true, color = R.color.white, view = flMineHelpBar)
    }

    override fun initView() {

        ivAppBack.setOnClickListener { finish() }

        rvMineHelpBody.adapter = mHelpAdapter.apply {
            setOnItemClickListener { _, _, position ->
                val itemData = getItem(position)
                MineRichTextActivity.openId(
                    activity = this@MineHelpActivity,
                    title = itemData.title,
                    id = itemData.id
                )
            }
        }
    }

    override fun initData() {
        viewModel.articleList("problem")
    }

    override fun initViewMode() {
        viewModel.articleListLiveData.observe(this as LifecycleOwner, { response ->
            if (response.status != Status.SUCCESS)
                return@observe
            val data = response.data?.data
                ?: return@observe
            mHelpAdapter.setNewInstance(data)
        })
    }

}